<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 商品评论
 * 
 * @author  : $Author: spike $
 * @date    : $Date: 2014-08-06 17:05:36 +0800 (三, 2014-08-06) $
 * @version : $Id: comment.php 126 2014-08-06 09:05:36Z spike $
 * @rev     : $Revision: 126 $
 */
class Comment extends CI_Controller 
{  
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * [浏览]
     */
    public function browse()
    {
        $params = $this->input->get();
        if($params)
        {
            $this->load->model('Comment_model');
            $list = $this->Comment_model->browse_comment($params, $params['page'], $params['size']);

            $this->load->library('pagination');
            $config['total_rows'] = $list['total'];
            $config['per_page']   = $list['size'];
            $config['suffix']     = '#data-table';

            $this->pagination->initialize($config); 
            $pagination = $this->pagination->create_links();
        }

        // 统计
        $this->load->dao('Comment_dao');
        $total = $this->Comment_dao->count(array(
            'is_delete' => UNDELETED
        ));

        $data = array(
            'default'        => $params ? $params : array(),
            'total'          => $total,
            'list'           => $list,
            'pagesize'       => $this->config->item('pagesize'),
            'comment_status' => $this->config->item('comment_status'),
            'pagination'     => $pagination,
        );

        $this->load->view('home/header.tpl', $data);
        $this->load->view('comment/browse.tpl');
        $this->load->view('home/footer.tpl');
    }

    /**
     * [改变状态]
     */
    public function change_status($sn = NULL)
    {
        $act     = $this->input->get('act');
        $is_ajax = $this->input->get('is_ajax');

        $this->load->model('Comment_model');
        if( FALSE === $this->Comment_model->change_comment_status($sn, $act))
        {
            if($is_ajax === '1')
            {
                json_exit($this->Comment_model->get_error());
            }
        }
        else
        {
            if($is_ajax === '1')
            {
                json_exit('操作成功', TRUE);
            }
        }
    }

}
/* End of file */